    
<?php include_partial('basketPage/progress', array('node' => $node)) ?>
<form action="<?php echo LinkGen::getInstance(LinkGen::STRUCTURE_ACTIONS)->link(null, array('module' => 'basketPage', 'action' => 'submitAddresses')) ?>" method="post">
    
    <div id="user-forms">  
    <?php
    include_partial('basketPage/userAddressBlock', array('label' => __('billing address'),
	'form' => $billingAddressForm,
	'type' => 'billing'
    ))
    ?>
    <?php
    include_partial('basketPage/userAddressBlock', array('label' => __('shipping address'),
	'form' => $shippingAddressForm,
	'type' => 'shipping'
    ))
    ?>
	    
    <div class="clearboth"></div>
    </div>
	    
	    
    <p style="float:left;"><a class="button_link" id="addresses_form_submit" href="#"><span><?php echo __('vormista ost') ?></span></a></p>
    <div class="clearboth"></div>
	
</form>


<?php //use_stylesheet('/backend_css_js/js/prompt/style.css') ?>
<?php //use_javascript('/backend_css_js/js/prompt/scripts.js') ?>
<script type="text/javascript">

jQuery('#addresses_form_submit').click(function(e){
	e.preventDefault();

	var form = jQuery(this).parents('form');
        jQuery('#user-forms').mask('<?php echo __('loading');?>');
    jQuery.post(form.attr('action'), form.serialize(), function(data){
		if(data.status == 200){
			window.location = data.redirect;
		}else{
			for(formMsg in data.messages){
                                flash = '';
				for(msg in data.messages[formMsg]){
					flash = flash + data.messages[formMsg][msg] + "<br />";
				}
                                console.log('#'+formMsg+'_error');
                                jQuery('#'+formMsg+'_error').html(flash);
                                
			}
                        jQuery('#user-forms').unmask();
//			$.prompt(flash,{
//				buttons: { OK:true }
//			});

		}
	},'json');


	return false;
});



    if(jQuery('#billing_address_addresses_different').is(':checked')){
	jQuery('fieldset.shipping').show();
    }

jQuery('#billing_address_addresses_different').change(function(){
    var item = jQuery(this);
    var shipping = jQuery('fieldset.shipping');
    if(item.is(':checked')){
	shipping.fadeIn();
	jQuery('#shipping_address_error').html('');
    }else{
	shipping.fadeOut()
    }
    
});


function toggleCompany(type){
    jQuery('.'+type+' .fname').toggle();
    jQuery('.'+type+' .lname').toggle();
    jQuery('.'+type+' .idcode').toggle();
    jQuery('.'+type+' .regcode').toggle();
    jQuery('.'+type+' .cname').toggle();    
       
}



    if(jQuery('#billing_address_is_company').is(':checked')){
        toggleCompany('billing');
    }
    jQuery('#billing_address_is_company').change(function(){
        toggleCompany('billing');
    })

    if(jQuery('#shipping_address_is_company').is(':checked')){
        toggleCompany('shipping');
    }
    jQuery('#shipping_address_is_company').change(function(){
        toggleCompany('shipping');
    })





</script>
